package com.yyc.tool.controller;

import com.yyc.tool.domain.Form4AppToken;
import com.yyc.tool.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("token管理")
@RestController
@RequestMapping("api/v1")
public class TokenController {

    private TokenService tokenService;

    @Autowired
    public void setTokenService(TokenService tokenService) {
        this.tokenService = tokenService;
    }

    @ApiOperation(value = "获取token", notes = "获取token")
    @PostMapping("token")
    public ResponseEntity<OAuth2AccessToken> getAppToken(@Validated @RequestBody Form4AppToken form4AppToken) throws Exception {
        return ResponseEntity.ok(tokenService.getAppToken(form4AppToken.getClientId(),form4AppToken.getClientSecret(),form4AppToken.getScope()));
    }
}
